package cn.chenfeifx.core.controls;

import cn.chenfeifx.core.controls.skins.CFAvatarSkin;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.Control;
import javafx.scene.control.Skin;
import javafx.scene.image.Image;

public class CFAvatar extends Control {

    private final DoubleProperty size = new SimpleDoubleProperty(50);
    private final DoubleProperty radius = new SimpleDoubleProperty(10);
    private final ObjectProperty<Image> image = new SimpleObjectProperty<>();

    public CFAvatar() {
        initialize();
    }

    public CFAvatar(Image image) {
        this.image.set(image);
        initialize();
    }

    public CFAvatar(Image image, double size, double radius) {
        this.image.set(image);
        this.size.set(size);
        this.radius.set(radius);
        initialize();
    }

    public DoubleProperty sizeProperty() {
        return size;
    }

    public double getSize() {
        return size.get();
    }

    public void setSize(double size) {
        this.size.set(size);
    }

    public DoubleProperty radiusProperty() {
        return radius;
    }

    public double getRadius() {
        return radius.get();
    }

    public void setRadius(double radius) {
        this.radius.set(radius);
    }

    public ObjectProperty<Image> imageProperty() {
        return image;
    }

    public void setImage(Image image) {
        this.image.set(image);
    }

    public Image getImage() {
        return image.get();
    }

    private void initialize() {
        setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);
    }

    @Override
    protected Skin<?> createDefaultSkin() {
        return new CFAvatarSkin(this);
    }
}
